var express = require('express')
var AnserModel = require('../db/answerModel')
var QuestModel = require("../db/questModel")

module.exports = function (req, res) {
    let id = req.params.id
    AnserModel.findOne({id: id}, function (error, answer) {
        QuestModel.findOne({id: answer.questId}, function (error, quest) {
            if (answer) {
                let response = Array()
                for (let i = 0; i < answer.answers.length; i++) {
                    let tmp = {}
                    tmp.no = answer.answers[i].no
                    tmp.type = quest.questions[i].type
                    tmp.answer = answer.answers[i].answer
                    response.push(tmp)
                }
                res.send({
                    id:answer.questId,
                    answer:response
                })
            } else {
                res.status(400).send({
                    status: 400,
                    message: "返回失败"
                })
            }
        })
    })
}